﻿function test()
{
	$.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php?show=test",
		  data:'',
		  dataType: 'html',
		  success: function(msg){
			  $('#test').html(msg);
		  },
	});
}

function success_mess(mess)
{//reference
    $("#content").html('');
	$("#mess").html(mess);
	$("#lodiv").show();
	$('#mess').delay(1000).fadeOut('slow');
}

function show_content()
{
    $("#content").show("slow");
}

function hide_content()
{
    $("#content").hide("slow");
}

function show_question_table()
{
    $('#questiontable').show("slow");
}

function keypress(e){//reference
    var keypressed = null;
    if (window.event)
    {
        keypressed = window.event.keyCode;
    }
    else
    { 
        keypressed = e.which;
    }
    
    if (keypressed < 48 || keypressed > 57)
    {
        if (keypressed == 8 || keypressed == 127)
        {
            return;
        }
        return false;
    }
}  

function filter()
{
	//filter tìm kiếm
	$(".filterable tr:has(td)").each(function(){
		var t = $(this).text().toLowerCase(); //all row text
		$("<td class=\'indexColumn\'></td>")
			.hide().text(t).appendTo(this);
		});//each tr
	$("#FilterTextBox").keyup(function(){
		var s = $(this).val().toLowerCase().split(" ");
		//show all rows.
		$(".filterable tr:hidden").show();
		$.each(s, function(){
			$(".filterable tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
		});//each
	});//key up.	
}

function filter_questionaire_subject(type)
{
    filterable = type+"_filterable";
	//filter tìm kiếm
	$("."+filterable+" tr:has(td)").each(function(){
		var t = $(this).text().toLowerCase(); //all row text
		$("<td class=\'indexColumn\'></td>")
			.hide().text(t).appendTo(this);
		});//each tr
	$("#"+type+"_FilterTextBox").keyup(function(){
		var s = $(this).val().toLowerCase().split(" ");
		//show all rows.
		$("."+filterable+" tr:hidden").show();
		$.each(s, function(){
			$("."+filterable+" tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
		});//each
	});//key up.	
}

//dung cho search phieu khao sat, trong file manage_questionaire.php
function survey_questionaire_result()
{
    var search_array = new Array();
    search_array[0] = '';
    if($('#cboprogram').val() != null)
        search_array[0] = search_array[0] + $('#cboprogram').val().toLowerCase();
    if($('#cbostatus').val() != null)
        search_array[0] = search_array[0] + $('#cbostatus').val();
    //search_array[0] = $('#cboprogram').val().toLowerCase() + $('#cbostatus').val();
	//show all rows.
	$(".filterable tr:hidden").show();
	$.each(search_array, function(){
		$(".filterable tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
	});//each	
}

//UNUSE__________dung cho chuc nang manage blackbox user
function subject_filter()
{
	//filter tìm kiếm
	$(".filterable tr:has(td)").each(function(){
		var t = $(this).text().toLowerCase(); //all row text
		$("<td class=\'indexColumn\'></td>")
			.hide().text(t).appendTo(this);
		});//each tr
	$("#FilterTextBox").keyup(function(){
		var s = $(this).val().toLowerCase().split(" ");
		//show all rows.
		$(".filterable tr:hidden").show();
		$.each(s, function(){
			$(".filterable tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
		});//each
	});//key up.
    $("#cboprogram").change(function(){
        var search_array = new Array(); 
		search_array[0] = $(this).val().toLowerCase() + $('#cboassign').val();
		//show all rows.
		$(".filterable tr:hidden").show();
		$.each(search_array, function(){
			$(".filterable tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
		});//each
	});//key up.
    $("#cboassign").change(function(){
		//var s = $('#cboprogram').val().toLowerCase();
        var search_array = new Array(); 
		search_array[0] = $('#cboprogram').val().toLowerCase() + $(this).val();
		//show all rows.
		$(".filterable tr:hidden").show();
		$.each(search_array, function(){
			$(".filterable tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
		});//each
	});//key up.	
}

function clear_filter()
{
    $("#FilterTextBox").val("");
    //show all rows.
	$(".filterable tr:hidden").show();
    load_question_add_survey();
}
//ham chi dung cho add questiont trong edit survey
function clear_filter_edit_only()
{
    $("#FilterTextBox").val("");
    //show all rows.
	$(".filterable tr:hidden").show();
    load_question_add_survey_edit_only();
}

//ham dung rieng cho edit survey, save tam id program dang chon
function save_program_id_edit_only(cbpro)
{
    //alert(cbpro.value);
    $("#id_txtid_pro").val(cbpro.value);
}

//dung cho filter learning outcome, trong do questionaire---UNUSE
function checked_filter()
{
    var search_array = new Array(); 
	search_array[0] = $('#cbostatus').val().toLowerCase();
	//show all rows.
	$(".filterable tr:hidden").show();
	$.each(search_array, function(){
		$(".filterable tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
	});//each	
}

 //filter hien checkbox da chon,dung trong questionaire, load input, output, subject, survey detail
 function checkbox_filter()
 {
    var s = $('#cbo_checked').val();
    $(".filterable tr:hidden").show();
    if(s == 'checked')
    {
        $(".filterable tr:visible :checkbox").each(function() {
            if(!$(this).is(':checked'))
            {
                $("#selected"+$(this).val()).hide();
            }
        });
    }
    else if(s == 'uncheck')
    {
        $(".filterable tr:visible :checkbox").each(function() {
            if($(this).is(':checked'))
            {
                //alert($(this).val());
                $("#selected"+$(this).val()).hide();
            }
        });
    }
 }

/*******************************************************************************************************************************************************************
 * 								Dynamic add and remoce textbox
 ***************************************************************************************************************************************************************/
function add_textbox()
{
    //so txt option toi da
    var max_textbox = 20;
    
    //index txt da add
    var counter = parseInt($("#id_counter").val());
    counter++;
    
    
    //so luong txt hien co
    var n = 0;
    $("[id^=txtOpt]").each(function(){ 
            n++;               
    });
    
    //kiem tra gioi han add
    if(n >= max_textbox){
            alert("Only "+ max_textbox +" textboxes allow");
            return false;
	}   
    
    //tao txt option moi
	var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
    var path_image = "../image/";
    var temp = '<img style="cursor:pointer;" src="'+path_image+'delete.png" onclick="remove_textbox('+counter+');"/>';
	newTextBoxDiv.html('<input type="text" name="textbox' + counter + '" id="txtOpt' + counter + '" placeholder="Option '+ counter +'" size="80" onblur="check_all_textbox()">'+temp);
    newTextBoxDiv.appendTo("#TextBoxesGroup");
    
    $("#divCheck").html('Please fill all options!');
    $("#id_txtCheck").val('');
    $("#id_counter").val(counter);
}

function remove_textbox(txt)
{
    //so txt option toi thieu
    var min_textbox = 2;
    
    //so luong txt hien co
    var n = 0;
    $("[id^=txtOpt]").each(function(){ 
        n++;              
    });
    //kiem tra gioi han so luong txt option
    if(n <= min_textbox){
          alert("There must be at least 2 options");
          return false;
    }
    
    //xoa option dc chon
    $("#TextBoxDiv" + txt).remove();
    check_all_textbox();
}

function check_all_textbox(){
    //dem so option khong hop le
    var n = 0;
    //var str = '';
    var str2 = '';
    $("[id^=txtOpt]").each(function(){ 
        if ($(this).val().length == 0) {
            n++;
        }
        else{
            //save to option cache
            //str = str + $(this).val() + "~";
            str2 = str2 + '<input type="checkbox" checked="checked" name="arr_opt[]" value="'+ $(this).val() +'">'+$(this).val();
        }             
    });
    
    //thong bao options
    if (n > 0)
    {
        $("#divCheck").html(get_string('blank3', 'local_blackboxsurvey'));
        $("#id_txtCheck").val('');
    }
    else
    {
        $("#divCheck").html('');
        $("#id_txtCheck").val('Checked');
        //$("#id_opt_cache").val(str);
        $("#div_arr_opt").html(str2);
    }
    
}

//Highligh các dòng được đánh dấu chọn trong table//reference 
function highlight(checkbox) {
	if (document.getElementById) {
      var tr = eval("document.getElementById(\"selected" + checkbox.value + "\")");
	}
	else {
      return;
	}
	if (tr.style) {
		if (checkbox.checked)
			tr.className = "highlight";
		else
			tr.className = "subject";
	}
}

//Highligh cac dong duoc chon trong input subject table----UNUSE
function insub_highlight(checkbox) {
	if (document.getElementById) {
      var tr = eval("document.getElementById(\"insub_selected" + checkbox.value + "\")");
	}
	else {
      return;
	}
	if (tr.style) {
		if (checkbox.checked)
			tr.className = "highlight";
		else
			tr.className = "subject";
	}
}

//Highligh cac dong duoc chon trong output subject table----UNUSE
function outsub_highlight(checkbox) {
	if (document.getElementById) {
      var tr = eval("document.getElementById(\"outsub_selected" + checkbox.value + "\")");
	}
	else {
      return;
	}
	if (tr.style) {
		if (checkbox.checked)
			tr.className = "highlight";
		else
			tr.className = "subject";
	}
}

/*******************************************************************************************************************************************************************
 * 											                          USE FOR MATCHING MANAGEEENT
 ******************************************************************************************************************************************************************/
 //hien match log
 function show_logs(id_bbsurvey){
    $.fn.colorbox({
			width:"900px", 
            href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=show_logs&id_bbsurvey="+id_bbsurvey,
			title:"",
			height:"90%", 
			iframe:true,
			onClosed:function(){       
			}
    });
}
//show hide checkbox teach course
function show_hide_teach_course_cb()
{
    $(":checkbox").each(function(){
        if($(this).is(':checked'))
        {
            $(":checkbox").each(function() {
            if(!$(this).is(':checked'))
                $(this).hide();
            });
            return;
        }
    });  
}
 //hien mon de add teach course for input
 function load_input_course_teach(id_input,id_bbsurvey){
    $.fn.colorbox({
			width:"100%", 
			//href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=add_question_edit_survey&id="+survey_id+"&array_ques="+array_ques,
            href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_input_course_teach&id="+id_input,
			title:"",
			height:"100%", 
			iframe:true,
			onClosed:function(){			 
				update_input_management(id_bbsurvey);
                                
			}
    });
}
 //hien colorbox cua input management
 function show_input_colorbox(id_bbsurvey)
 {
    var check_admin = $('#id_check_admin').val();
    $.fn.colorbox({
			width:"1024px",
			href:M.cfg.wwwroot+"/local/blackboxsurvey/matcher/input_management.php?id_bbsurvey="+id_bbsurvey+"&s="+check_admin,
			title:"",
			height:"90%",
			iframe:true, 
			onClosed:function(){			 
			}
    });
 }
 
  //add output learning outcome trong matching
 function update_input_management(id_bbsurvey)
 {
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'update_input_management',
                    "id_bbsurvey": id_bbsurvey
                },
		  dataType: 'html',
		  success: function(msg){
		      $('#ipm').html(msg);
		  },
	});
 } 
 //delete uncmatched output
 function delete_unmatched_output(id_output, id_bbsurvey, alert_str)
 {
    if(confirm(alert_str)) {
    //if(confirm("Are you sure you want to delete this output?")) {
        $.ajax({
    		  type: 'GET',
    		  url: "../ajax.php",
    		  data: { 
                        "show": 'delete_unmatched_output',
                        "id_output": id_output,
                        "id_bbsurvey": id_bbsurvey
                    },
    		  dataType: 'html',
    		  success: function(msg){
    		     //update lai output
                 $('#opm').html(msg);
    		  },
    	});
    }
 }

//delete matched input
 function delete_unmatched_input(id_input, id_bbsurvey, alert_str)
 {
    //if(confirm("Are you sure you want to delete this input?")) {
    if(confirm(alert_str)) {
        $.ajax({
    		  type: 'GET',
    		  url: "../ajax.php",
    		  data: { 
                        "show": 'delete_unmatched_input',
                        "id_input": id_input,
                        "id_bbsurvey": id_bbsurvey
                    },
    		  dataType: 'html',
    		  success: function(msg){
    		     //update lai output
                 $('#ipm').html(msg);
    		  },
    	});
    }
 }

  //hien colorbox cua output management
 function show_output_colorbox(id_bbsurvey)
 {
    var check_admin = $('#id_check_admin').val();
    $.fn.colorbox({
			width:"1024px",
			href:M.cfg.wwwroot+"/local/blackboxsurvey/matcher/output_management.php?id_bbsurvey="+id_bbsurvey+"&s="+check_admin,
			title:"",
			height:"90%",
			iframe:true, 
			onClosed:function(){
			     
			}
    });
 }
 

 //add output learning outcome trong matching
 function add_teachcourse_forInput(id_input, id_teach_course, id_subject, id_bbsurvey)
 {    
        
    if($('#cb'+id_teach_course).is(':checked')) {
        var action = "add";
        $(":checkbox").each(function() {
        if(!$(this).is(':checked'))
        {
            $(this).hide();
        }
    });                
    } else {
        var action = "remove";
        $(":checkbox").each(function() {
            $(this).show();
        });        
    }
        
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_teachcourse_forInput',
                    "id_input": id_input,
                    "id_subject": id_subject,
                    "id_teach_course": id_teach_course,
                    "id_bbsurvey": id_bbsurvey,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
		      		      
		  },
	});
 } 
  
  function confirm_save_matching_subject(alert_str)
  {   
    if(confirm(alert_str))
    //if(confirm('Are you sure you want to save these matching data?'))
        return true;
    return false;
 }
   //update table matching sau khi matching output
 function update_matching_table(id_bbsurvey, id_subject, id_output)
 {
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'update_matching_table',
                    "id_output": id_output, 
                    "id_bbsurvey": id_bbsurvey,
                    "id_subject": id_subject
                },
		  dataType: 'html',
		  success: function(msg){
		     //$('#matched_input'+id_output).html(msg);
             $('#matching_table').html(msg);
		  },
	});
 }
   //add output learning outcome trong do & edit questionaire
 function add_matching_outin(id_matching, id_output, id_input)
 {
    if($('#cb'+id_input).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_matching_outin',
                    "id_matching": id_matching,
                    "id_output": id_output,
                    "id_input": id_input,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
  //hien colorbox danh sach input de matching cho 1 output
 function show_matching_outin_colorbox(id_bbsurvey, id_subject, id_output)
 {
    $.fn.colorbox({
			width:"800px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=show_matching_outin&id_bbsurvey="+id_bbsurvey+"&id_subject="+id_subject+"&id_output="+id_output,
			title:"",
			height:"80%", 
			iframe:true, 
			onClosed:function(){
                update_matching_table(id_bbsurvey, id_subject, id_output);
			}
    });
 }
 //hien course map thong qua colorbox
 function show_course_map_colorbox(id_bbsurvey)
 {
    $.fn.colorbox({
			width:"100%", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/matcher/course_map.php?id_bbsurvey="+id_bbsurvey,
			title:"",
			height:"100%", 
			iframe:true, 
			onClosed:function(){
			}
    });
 }
 
 //an hien noi dung cau tra loi
 function show_hide_answer_content(k)
 {
    $("#display_content"+k).toggle(150);
    $("#show"+k).toggle();
    $("#hide"+k).toggle();
 }
 /*function show_hide_answer_content(k,i)
 {

    if(i == 1)
    {
        $("#display_content"+k).show(150);
        $("#show"+k).hide();
        $("#hide"+k).show();
    }
    else if(i == -1)
    {
        $("#display_content"+k).hide(150);
        $("#show"+k).show();
        $("#hide"+k).hide();
    }
 }*/
 //hien color hox chon subject de matching
 function show_match_subject_list_colorbox(id_bbsurvey)
 {
    var check_admin = $('#id_check_admin').val();
    $.fn.colorbox({
			width:"950px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/matcher/manage_subject.php?id_bbsurvey="+id_bbsurvey+"&s="+check_admin,
			title:"",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
			}
    });
 }
 
 
 
 //View matching
 function view_matching_subject_form(id_bbsurvey, id_subject){
    var check_admin = $('#id_check_admin').val();               
    parent.$.fn.colorbox.close();
    var url = "view_matching.php?id_bbsurvey="+id_bbsurvey+"&id_subject="+id_subject;
    parent.window.location = url;
 }
 
 //hien form matching
 function show_matching_subject_form(id_bbsurvey, id_subject, action, alert_str)
 {    
    var check_admin = $('#id_check_admin').val();
    if(action == 'init')
    {
        //if(confirm("Are you sure you want to matching this subject?")) {
        if(confirm(alert_str)) {   
            parent.$.fn.colorbox.close();
            var url = "match_subject.php?id_bbsurvey="+id_bbsurvey+"&id_subject="+id_subject+"&s="+check_admin;
            parent.window.location = url;
        }
    }
    else if (action == 'edit')
    {
        //if(confirm("Are you sure you want to continue matching this subject?")) {  
        if(confirm(alert_str)) { 
            parent.$.fn.colorbox.close();
            var url = "edit_matching.php?id_bbsurvey="+id_bbsurvey+"&id_subject="+id_subject+"&s="+check_admin;
            parent.window.location = url;
        }
    }
 }
/*******************************************************************************************************************************************************************
 * 											                          USE FOR QUESTIONAIRE
 ******************************************************************************************************************************************************************/
 function set_action_questionaire(action, alert_str)
{   
    if(action == 1)
    {
        //if(confirm('Are you sure you want to submit this questionnaire?'))
        if(confirm(alert_str))
        {
            $("#id_txt_action").val(action);
            return true;
        }
        return false;
    }
    if(action == -1)
    {
        if(confirm(alert_str))
        {
            $("#id_txt_action").val(action);
            return true;
        }
        return false;
    }
}
 //add output learning outcome trong do & edit questionaire
 function add_output_request_questionaire(id_qn,id_request)
 {
    if($('#cb'+id_request).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_output_request_questionaire',
                    "id_qn": id_qn,
                    "id_rq": id_request,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
//hien colorbox load output from request, dung cho do &edit questionaire
function load_request_add_questionaire_colorbox(id_qn)
{
    //var qn_id = $('#id_qn_id').val();
    $.fn.colorbox({
			width:"1024px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_request_do_questionaire&qn_id="+id_qn,
			title:"",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_outlo_questionaire(id_qn);
                show_outsub_list_questionaire(id_qn);//cap nhat danh sach mon cung cap
                set_viewed_request(id_qn);//set tinh trang de view request
			}
    });
}
// set tinh trang da xem cho new request
function set_viewed_request(id_qn)
{
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'set_viewed_request',
                    "id_qn": id_qn
                },
		  dataType: 'html',
		  success: function(msg){
 		 	$('#request_mess').html('');
		  },
	});
}
 //add input learning outcome trong do questionaire
 function add_outlo_index_questionaire(id_output,id_lo)
 {
    if($('#cb'+id_lo).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_outlo_index_questionaire',
                    "id_output": id_output,
                    "id_lo": id_lo,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
 //hien danh sach leaning outcome index cua new input, dung cho do & edit questionaire
function load_outlo_index_do_questionaire(id_output,id_program,id_qn)
{   
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_outlo_index_do_questionaire&id_output="+id_output+"&id_program="+id_program,
			title:"",
			height:"70%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_outlo_questionaire(id_qn);//cap nhat danh sach input
			}
    });
}
 //add subject cho 1 input, dung trong do questionaire
 function add_output_subject_questionaire(id_output,id_subject)
 {
    if($('#cb'+id_subject).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_output_subject_questionaire',
                    "id_output": id_output,
                    "id_subject": id_subject,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
//hien danh sach mon output, dung cho do & edit questionaire
function load_output_sub_do_questionaire(id_output,id_program,id_qn, id_subject)
{   
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_output_sub_do_questionaire&id_output="+id_output+"&id_program="+id_program+"&id_qn="+id_qn+"&id_subject="+id_subject,
			title:"",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_outlo_questionaire(id_qn);//cap nhat danh sach input
                show_outsub_list_questionaire(id_qn);//cap nhat danh sach mon cung cap
			}
    });
}
//hien danh sach mon output
function show_outsub_list_questionaire(id_qn){
    //alert($('#id_txtid').val());
    $.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
		  data: { 
                    "show": 'show_outsub_list_questionaire',
                    "id_qn": id_qn
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#tb_selected_outsub').html(msg);
		  },
	});
}
 //remove output learning outcome trong do & edit questionaire
function remove_outlo_questionaire(id)
{
    if(confirm("Are you sure you want to remove this output learning outcome?")){
        $.ajax({
    		  type: 'GET',
    		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
    		  data: { 
                        "show": 'remove_outlo_questionaire',
                        "id": id
                    },
    		  dataType: 'html',
    		  success: function(msg){
                    show_outsub_list_questionaire($('#id_qn_id').val());//cap nhat danh sach mon cung cap
     		 	   show_outlo_questionaire($('#id_qn_id').val());//cap nhta danh sach input
                   
    		  },
    	});
    }
}
 //add output learning outcome trong do & edit questionaire
 function add_load_outlo_questionaire(id_qn,id_lo)
 {
    if($('#cb'+id_lo).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_load_outlo_questionaire',
                    "id_qn": id_qn,
                    "id_lo": id_lo,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
//hien colorbox load LO from syllabus, dung cho do & edit questionaire
function load_outlo_add_questionaire_colorbox(id_qn,id_program)
{
    //var qn_id = $('#id_qn_id').val();
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_outlo_do_questionaire&qn_id="+id_qn+"&id_program="+id_program,
			title:"Add Learning Outcome",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_outlo_questionaire(id_qn);
                show_outsub_list_questionaire(id_qn);//cap nhat danh sach mon cung cap
			}
    });
}
//hien danh sach output learning outcome da chon
function show_outlo_questionaire(id_qn){
    //alert($('#id_txtid').val());
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'show_outlo_questionaire',
                    "id_qn": id_qn
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#selected_outlo').html(msg);
		  },
	});
    //hiem danh sach mon cung cap
}
 //hien colorbox add new output, dung cho do & edit questionaire
function add_edit_new_output_questionaire_colorbox(id_qn, id_output, action)
{
    //var qn_id = $('#id_qn_id').val();
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/lecturer/add_output.php?id_qn="+id_qn+"&id_output="+id_output+"&action="+action,
			title:"",
			height:"700px", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_outlo_questionaire(id_qn);
                
			}
    });
}
//add input learning outcome trong do questionaire
 function add_inlo_index_questionaire(id_input,id_lo)
 {
    if($('#cb'+id_lo).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_inlo_index_questionaire',
                    "id_input": id_input,
                    "id_lo": id_lo,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
//hien danh sach leaning outcome index cua new input, dung cho do & edit questionaire
function load_inlo_index_do_questionaire(id_input,id_program,id_qn)
{   
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_inlo_index_do_questionaire&id_input="+id_input+"&id_program="+id_program,
			title:"",
			height:"70%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_inlo_questionaire(id_qn);//cap nhat danh sach input
			}
    });
}
//hien colorbox add new input, dung cho do & edit questionaire
function add_edit_new_input_questionaire_colorbox(id_qn, id_input, action)
{
    //var qn_id = $('#id_qn_id').val();
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/lecturer/add_input.php?id_qn="+id_qn+"&id_input="+id_input+"&action="+action,
			title:"",
			height:"700px", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_inlo_questionaire(id_qn);
                
			}
    });
}
//hien danh sach mon cung cap
function show_insub_list_questionaire(id_qn){
    //alert($('#id_txtid').val());
    $.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
		  data: { 
                    "show": 'show_insub_list_questionaire',
                    "id_qn": id_qn
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#tb_selected_insub').html(msg);
		  },
	});
}
 //add subject cho 1 input, dung trong do questionaire
 function add_input_subject_questionaire(id_input,id_subject)
 {
    if($('#cb'+id_subject).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_input_subject_questionaire',
                    "id_input": id_input,
                    "id_subject": id_subject,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
 
//hien danh sach mon cung cap cua input, dung cho do questionaire
function load_input_sub_do_questionaire(id_input,id_program,id_qn,id_subject)
{   
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_input_sub_do_questionaire&id_input="+id_input+"&id_program="+id_program+"&id_qn="+id_qn+"&id_subject="+id_subject,
			title:"Input Subject",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_inlo_questionaire(id_qn);//cap nhat danh sach input
                show_insub_list_questionaire(id_qn);//cap nhat danh sach mon cung cap
			}
    });
}

//remove input learning outcome trong do & edit questionaire
function remove_inlo_questionaire(id)
{
    if(confirm("Are you sure you want to remove this input learning outcome?")){
        $.ajax({
    		  type: 'GET',
    		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
    		  data: { 
                        "show": 'remove_inlo_questionaire',
                        "id": id
                    },
    		  dataType: 'html',
    		  success: function(msg){
                    show_insub_list_questionaire($('#id_qn_id').val());//cap nhat danh sach mon cung cap
     		 	   show_inlo_questionaire($('#id_qn_id').val());//cap nhta danh sach input
                   
    		  },
    	});
    }
}
//hien danh sach input learning outcome da chon
function show_inlo_questionaire(id_qn){
    //alert($('#id_txtid').val());
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'show_inlo_questionaire',
                    "id_qn": id_qn
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#selected_inlo').html(msg);
		  },
	});
    //hiem danh sach mon cung cap
    //show_insub_list_questionaire(id_qn);
}

 //add input learning outcome trong do questionaire
 function add_load_inlo_questionaire(id_qn,id_lo)
 {
    if($('#cb'+id_lo).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_load_inlo_questionaire',
                    "id_qn": id_qn,
                    "id_lo": id_lo,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
//hien colorbox add question, dung cho create survey
function load_inlo_add_questionaire_colorbox(id_qn,id_program)
{
    //var qn_id = $('#id_qn_id').val();
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_inlo_do_questionaire&qn_id="+id_qn+"&id_program="+id_program,
			title:"Add Learning Outcome",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                show_inlo_questionaire(id_qn);
			}
    });
}
//dung cho do questionaire survey, remove selected output subject----UNUSE
function outsub_remove(id)
{
    $('#outsub_tr'+id).remove();
    $('#outsub_cb'+id).prop('checked', false);
    var tr = eval("document.getElementById(\"outsub_selected" + id + "\")");
    tr.className = "subject";
}

//dung cho do questionaire, hien danh sach output subject da chon---UNUSE
function add_row_to_table_outsub(id, name)
{
	if ($('#outsub_cb'+id).is(':checked'))
	{
        path_image = M.cfg.wwwroot+"/local/blackboxsurvey/image/",
		//them dong của bảng selected matcher
		$('#tb_selected_outsub').append('<tr class="subject" id="outsub_tr'+id+'"><td align="center" onclick="outsub_remove('+ id +')"><img src="' + path_image + 'delete.png"/></td><td>'+name+'</td></tr>');
		$('#selected_outsub').show();
	}
	else
	{
		//xoa dong của bảng selected matcher
		$('#outsub_tr'+id).remove();
	}
}

//dung cho do_questionaire.php, hien danh sach output subject---UNUSE
function load_outsub_do_questionaire($id_program)
{   
    if($('#outsubtable').html() == "")
    {
    	$.ajax({
    		  type: 'GET',
    		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
    		  data: { 
                        "show": 'outsubtable',
                        "id_program": $id_program
                    },
    		  dataType: 'html',
    		  success: function(msg){
    			  $('#outsubtable').html(msg);
                  filter_questionaire_subject("outsub");
    			  //filter();
    		  },
    		  error: function()
    		  {
    			$('#outsubtable').html('<div id="mess" class="error">Loading Error</div>');
    		  }
    	});
    }
    filter_questionaire_subject("outsub");
}
//dung cho do questionaire survey, remove selected input subject---UNUSE
function insub_remove(id)
{
    $('#insub_tr'+id).remove();
    $('#insub_cb'+id).prop('checked', false);
    var tr = eval("document.getElementById(\"insub_selected" + id + "\")");
    tr.className = "subject";
}

//dung cho do questionaire, hien danh sach input subject da chon--UNUSE
function add_row_to_table_insub(id, name)
{
	if ($('#insub_cb'+id).is(':checked'))
	{
        path_image = M.cfg.wwwroot+"/local/blackboxsurvey/image/",
		//them dong của bảng input subject
		$('#tb_selected_insub').append('<tr class="subject" id="insub_tr'+id+'"><td align="center" onclick="insub_remove('+ id +')"><img src="' + path_image + 'delete.png"/></td><td>'+name+'</td></tr>');
		$('#selected_insub').show();
	}
	else
	{
		//xoa dong của bảng selected matcher
		$('#insub_tr'+id).remove();
	}
}

//dung cho do_questionaire.php
/*function load_insub_do_questionaire($id_program)
{   
    if($('#insubtable').html() == "")
    {
    	$.ajax({
    		  type: 'GET',
    		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
    		  data: { 
                        "show": 'insubtable',
                        "id_program": $id_program
                    },
    		  dataType: 'html',
    		  success: function(msg){
    			  $('#insubtable').html(msg);
                  filter_questionaire_subject("insub");
    			  //filter();
    		  },
    		  error: function()
    		  {
    			$('#insubtable').html('<div id="mess" class="error">Loading Error</div>');
    		  }
    	});
    }
    filter_questionaire_subject("insub");
}*/

//bat dau lam phieu khao sat, dung cho do_questionaire.php
function do_questionaire(idbbsurvey, idsubject, str)
{
    //if(confirm("Are you sure you want to begin this survey?")) {
    if(confirm(str)) {
        var url = M.cfg.wwwroot+"/local/blackboxsurvey/lecturer/do_questionaire.php?idbbsurvey="+idbbsurvey+"&idsubject="+idsubject;
        window.location = url;
    }
}
//Edit questionaire
function edit_questionaire(idbbsurvey, idsubject, str)
{
    //if(confirm("Are you sure you want to edit this survey?")) {
    if(confirm(str)) {
        var url = M.cfg.wwwroot+"/local/blackboxsurvey/lecturer/edit_questionaire.php?idbbsurvey="+idbbsurvey+"&idsubject="+idsubject;
        window.location = url;
    }
}
//bat dau lam phieu khao sat, dung cho do_questionaire.php
function view_questionaire(idbbsurvey, idsubject)
{
    //if(confirm("Are you sure?")) {
        var url = M.cfg.wwwroot+"/local/blackboxsurvey/lecturer/view_questionaire.php?idbbsurvey="+idbbsurvey+"&idsubject="+idsubject;
        window.location = url;
    //}
}
/*******************************************************************************************************************************************************************
 * 											                          USE FOR BLACKBOX SURVEY
 ******************************************************************************************************************************************************************/
 //dung cho survey detail
function survey_detail_filter()
{
    filter();
    $("#cbo_status_survey").change(function(){
        var search_array = new Array(); 
		search_array[0] = $('#cbo_status_survey').val();
		//show all rows.
		$(".filterable tr:hidden").show();
		$.each(search_array, function(){
			$(".filterable tr:visible .indexColumn:not(:contains(\'"+ this + "\'))").parent().hide();
		});//each
        show_send_mail_icon();
	});//key up.	
}
 //chon visible send mail checkbox trong survey details
 function set_all_visile_checkbox()
 {
    $(".filterable tr:visible :checkbox").each(function() {
        $(this).prop('checked', $('#check_all').is(':checked'));
        //highligh nhung dong da chon
        if($(this).val() != 'x')
        {
            var tr = eval("document.getElementById(\"selected" + $(this).val() + "\")");
        	if (tr.style) {
        		if ($(this).is(':checked'))
        			tr.className = "highlight";
        		else
        			tr.className = "subject";
        	}
        }
    });
    show_send_mail_icon();
 }
 
 //kiem tra co checkbox nao dc chon ko
 function show_send_mail_icon()
 {
    $('#check_all').prop('checked', false);
    $('#send_mail_icon').hide();
    $(".filterable tr:visible :checkbox").each(function() {
        if($(this).val() != 'x' && $(this).is(':checked'))
        {
            $('#check_all').prop('checked', true);
            $('#send_mail_icon').show();
            return;
        }
    });
 }
 //INDIVIDUAL Remind survey by email----UNUSE
function remind_survey(email1, email2, name, program, subject, start, end)
{
    //alert($('#cboquestype').val());
    //alert('Request sent!');
    $.ajax({
		  type: 'GET',
		  url: "../class/mail.php",
		  data: { 
                    //"id_program": id_program,
                    //"id_user": id_user,
                    //"id_subject": id_subject
                    'email1': email1,
                    'email2': email2,
                    'name': name,
                    'program': program,
                    'subject': subject,
                    'start': start,
                    'end': end
                },
		  dataType: 'html',
		  success: function(msg){
			  
              //alert(msg);
		  },
	});
}
 //SEND MAIL MULTIPLE,DUNG TRONG SURVEY DETAIL
 function send_mail()
 {
    if(confirm("Are you sure you want to send email to this user?")){
        var str = "";
        var count = 0;
        //lay du lieu de send mail
        $(".filterable tr:visible :checkbox").each(function() {
            if($(this).val() != 'x' && $(this).is(':checked'))
            {
                count++;
                str += "&mail"+count+"="+$(this).val();
                
            }
        });
        //alert(str);
        $.ajax({
    		  type: 'GET',
    		  url: "../sendmail/mail.php?count="+count+str,
    		  data: {},
    		  dataType: 'html',
    		  success: function(msg){
                  alert("Mail Sent!");
    		  },
    	});
    }
 }
 //load danh sach cau hoi de add vao survey
function load_question_add_survey()
{
    //alert($('#cboquestype').val());
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_question_to_survey',
                    "type_id": $('#cboquestype').val(),
                    "status": $('#cbostatus').val(),
                    "survey_id": $('#id_txtid').val()
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#questiontable').html(msg);
              filter();
		  },
	});
}

//hien colorbox add question, dung cho create survey
function load_question_add_survey_colorbox()
{
    var survey_id = $('#id_txtid').val();
    $.fn.colorbox({
			width:"900px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=add_question_create_survey&id="+survey_id,
			title:"Add Question",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				show_survey_question();
			}
    });
}

//dung cho create survey,referrence
function load_matcher_add_survey($id_bbsurvey)
{   
    if($('#matchertable').html() == "")
    {
    	$.ajax({
    		  type: 'GET',
    		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
    		  data: { 
                        "show": 'matchertable',
                        "id_bbsurvey": $id_bbsurvey
                    },
    		  dataType: 'html',
    		  success: function(msg){
    			  $('#matchertable').html(msg);
    			  filter();
    		  },
    		  error: function()
    		  {
    			$('#matchertable').html('<div id="mess" class="error">Loading Error</div>');
    		  }
    	});
    }
}

//dung cho create survey, reference
function add_row_to_table_matcher(id, name)
{
	if ($('#cb'+id).is(':checked'))
	{
        path_image = M.cfg.wwwroot+"/local/blackboxsurvey/image/",
		//them dong của bảng selected matcher
		$('#tb_selected_matcher').append('<tr id="tr'+id+'"><td>'+name+'</td><td align="center" onclick="remove_matcher('+ id +')"><img src="' + path_image + 'delete.png"/></td></tr>');
		$('#selected_matcher').show();
	}
	else
	{
		//xoa dong của bảng selected matcher
		$('#tr'+id).remove();
	}
}

//dung cho create survey
function remove_matcher(id)
{
    $('#tr'+id).remove();
    $('#cb'+id).prop('checked', false);
    var tr = eval("document.getElementById(\"selected" + id + "\")");
    tr.className = "subject";
}

//load danh sach cau hoi
function load_question_table()
{	
    
    $("#questiontable").hide("slow");
	$.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
		  data: { 
                    "show": 'questiontable'
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#questiontable').html(msg);
              $('#questiontable').show("slow");
		  },
	});
}

//hien thi ket qua tìm kiem cau hoi
function question_search_result()
{
    $.ajax({
		  type: 'GET',
		  url:"../ajax.php",
		  data: { 
                    "show": 'search_question',
                    "type_id": $('#cboquestype').val(),
                    "status": $('#cbostatus').val()
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#questiontable').html(msg);
		  },
	});
}

function survey_search_result()
{
    //var xxx = M.cfg.wwwroot + "/local/blackboxsurvey/ajax.php";
    //alert(xxx);
    //alert($('#cboquestype').val());
    $.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
		  data: { 

                    "show": 'search_survey',
                    "id_program": $('#cboprogram').val(),
                    "status": $('#cbostatus').val()
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#survey_able').html(msg);
		  },
	});
}

//hien danh sach cau hoi survey dc chon
function show_survey_question(){
    //alert($('#id_txtid').val());
    $.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
		  data: { 
                    "show": 'show_survey_question',
                    "survey_id": $('#id_txtid').val()
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#selected_question').html(msg);
		  },
	});
}
//hien thi danh sach cau hoi de add vao survey, chi dung cho edit survey
function load_question_add_survey_edit_only()
{
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_question_to_survey_edit_only',
                    "type_id": $('#cboquestype').val(),
                    "status": $('#cbostatus').val(),
                    "temp_ques": $('#id_txtquestion').val()
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#questiontable').html(msg);
              filter();
		  },
	});
}

//hien colorbox add question trong edit survey
function load_question_add_survey_edit_only_colorbox()
{
    var survey_id = $('#id_txtid').val();
    //var array_ques = $('#id_txt_temp_ques').val();
    $.fn.colorbox({
			width:"700px", 
			//href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=add_question_edit_survey&id="+survey_id+"&array_ques="+array_ques,
            href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=add_question_edit_survey&id="+survey_id,
			title:"Add Question",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				show_survey_question_edit_only();
			}
    });
}



//hien danh sach cau hoi survey dc chon
function show_survey_question_edit_only(){
    //alert($('#id_txtid').val());
    $.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
		  data: { 
                    "show": 'show_survey_question_edit_only',
                    "survey_id": $('#id_txtid').val()
                    //"temp_ques": $('#id_txt_temp_ques').val()
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#selected_question').html(msg);
		  },
	});
}

 //add cau hoi cho survey
 function add_survey_question(question_id)
 {
    if($('#cb'+question_id).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'add_survey_question',
                    "survey_id": $('#id_txtid').val(),
                    "question_id": question_id,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
 
 //edit survey
 function edit_survey(survey_id, edit_surveymess){
    //if(confirm("Are you sure you want to edit this survey?")) {
    if(confirm(edit_surveymess)) {
        var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/edit_survey.php?id="+survey_id;
        window.location = url;
    }
 }

//review survey
 function review_survey(survey_id){
        var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/review_survey.php?id="+survey_id;
        window.location = url;
 }
 
 //detail survey
 function detail_survey(survey_id){
        /*var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/survey_detail.php?id="+survey_id;
        window.location = url;*/
        $.fn.colorbox({
			width:"1200px", 
			href:'survey_detail.php?id='+survey_id,
			title:"",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				//question_search_result();
			}
		});
 }

//save survey question cache, chi su dung cho edit question
function save_survey_question_cache_edit_only()
{
    //alert($('#id_txtquestion').val());
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'save_survey_question_cache_edit_only',
                    "temp_ques": $('#id_txtquestion').val(),
                    "survey_id": $('#id_txtid').val()
                },
		  dataType: 'html',
		  success: function(msg){
		      //alert(msg);
		  },
	});
}

//add tam thoi cau hoi dc chọn truoc khi submit create survey, ham nay dung rieng cho edit survey
 function add_survey_question_edit_only(question_id)
 {
    if($('#cb'+question_id).is(':checked')) {
        //var action = "add";
         var str = $('#id_txtquestion').val() + "|" +question_id + "|";
    } else {
        //var action = "remove";
        var replace_str = "|" +question_id + "|";
        var str = $('#id_txtquestion').val().replace(replace_str, '');
    }
    //$('#id_txt_temp_ques').val(str);
    $('#id_txtquestion').val(str);
    save_survey_question_cache_edit_only();
 }
 
 //xoa tam survey question trong edit survey
function remove_survey_question_edit_only(question_id)
{
    //var replace_str = "|" + question_id + "|";
    //var str = $('#id_txt_temp_ques').val().replace(replace_str, '');
    //$('#id_txt_temp_ques').val(str);
    $.ajax({
    		  type: 'GET',
    		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
    		  data: { 
                        "show": 'remove_survey_question_edit_only',
                        "survey_id": $('#id_txtid').val(),
                        "question_id": question_id
                    },
    		  dataType: 'html',
    		  success: function(msg){
     		 	//show_survey_question();
                $('#selected_question').html(msg);
    		  },
   	});
}

//publish survey
 function publish_survey(id, publish_surveymess, successpublish_mess, cannotpub_mess, usedsurvey_mess){
    //if(confirm("Are you sure you want to publish this survey?")) {
    if(confirm(publish_surveymess)) {
        $('#lodiv').show();
        $('#lodiv').html('<div class="loading">Updating...</div>');
        $.ajax({
            type: 'GET',
            //url: M.cfg.wwwroot+"/local/blackboxsurvey/admin/publish_survey.php",
            url: 'publish_survey.php',
            data: { 
                    "id": id
                    },
            dataType: 'html',
            success: function(msg){
                if(msg == 'true'){//neu xoa thanh cong
                    $('#lodiv').html('<div id="mess" class="success"></div>');
                    success_mess(successpublish_mess);
                    //var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/manage_survey.php";
                    //window.location = url;
                    survey_search_result();
                }
                else if (msg == 'false')
                {
					survey_search_result();
                    //$('#lodiv').html('<script>alert("The survey has been used");</script>');
                    $('#lodiv').html('<script>alert(usedsurvey_mess);</script>');
                }
                //$('#test').html(msg);
                
            },
            error: function()
            {
                alert(cannotpub_mess);
                $('#lodiv').hide();
                $('#lodiv').html('');
            }
        });	
    }	
 }

function delete_survey(id, delete_surveymess, delete_successful) 
{
    //if(confirm("Are you sure you want to delete this survey?")) {
    if(confirm(delete_surveymess)) {
        $('#lodiv').show();
        $('#lodiv').html('<div class="loading">Processing...</div>');
        $.ajax({
            type: 'GET',
            url: M.cfg.wwwroot+"/local/blackboxsurvey/admin/delete_survey.php",
            //url: 'delete_survey.php',
            data: { 
			
                    "id": id
                    },
            dataType: 'html',
            success: function(msg){
                if(msg == 'true'){//neu xoa thanh cong
                    $('#lodiv').html('<div id="mess" class="success"><div>');
                    success_mess(delete_successful);
                    //var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/manage_survey.php";
                    //window.location = url;
                    survey_search_result();
                }
                else if (msg == 'false'){//xoa that bai
                    $('#lodiv').html('<script>alert("The survey has been used");</script>');
                }
                //$('#test').html(msg);
                
            },
            error: function()
            {
                alert('Can not delete survey');
                $('#lodiv').hide();
                $('#lodiv').html('');
            }
        });	
    }	
}

//remove survey question
function remove_survey_question(id)
{
    //if(confirm("Bạn có thực sự muốn xóa câu hỏi này không?")){
        $.ajax({
    		  type: 'GET',
    		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
    		  data: { 
                        "show": 'remove_survey_question_byID',
                        "id": id
                    },
    		  dataType: 'html',
    		  success: function(msg){
     		 	show_survey_question();
    		  },
    	});
   // }
}
 /*******************************************************************************************************************************************************************
 * 											                          USE FOR QUESTION
 ******************************************************************************************************************************************************************/
//load giao dien cua tung loai cau hoi
function load_question_form()
{	
    var typeid = $('#cboquestype').val();
    if(typeid == 1 || typeid == 4)//written question va yes no question
        var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/add_single_question.php?id="+typeid;
    if(typeid == 2 || typeid == 3)//multi choice question
        var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/add_multichoice_question.php?id="+typeid;
    window.location = url;
}

//load chi tiet cau hoi
function show_question_view(id_question) 
{	
	$.fn.colorbox({
			width:"600px",
			href:'../admin/view_question.php?id='+id_question,
			title:"Question View",
			height:"600px", 
			iframe:true, 
			onClosed:function(){
			}			
	});	
}

 //edit cau hoi
 function edit_question(question_id, editques_mess)
 {
    //if(confirm("Are you sure you want to delete this question?")) {
    if(confirm(editques_mess)) { 
	 $.fn.colorbox({
			width:"800px", 
			href:'edit_question.php?id='+question_id,
			title:"Edit Question",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				question_search_result();
			}
		});
    }
 }
 
 //edit multiple choice question
  function edit_multichoice_question(question_id, editques_mess)
 {
    if(confirm(editques_mess)) { 
	 $.fn.colorbox({
			width:"800px", 
			href:'edit_multichoice_question.php?id='+question_id,
			title:"Edit Question",
			height:"90%", 
			iframe:true, 
			onClosed:function(){
				question_search_result();
			}
		});
    }
 }
 
 function delete_question(id, deleteques_mess, delete_successful) 
{
    //if(confirm("Are you sure you want to delete this question?")) {
    if(confirm(deleteques_mess)) {
        $('#lodiv').show();
        $('#lodiv').html('<div class="loading">Deleting...</div>');
        $.ajax({
            type: 'GET',
            //url: M.cfg.wwwroot+"/local/blackboxsurvey/admin/delete_question.php",
            url: 'delete_question.php',
            data: { 
                    "id": id
                    },
            dataType: 'html',
            success: function(msg){
                if(msg == 'true'){//neu xoa thanh cong
                    $('#lodiv').html('<div id="mess" class="success"><div>');
                    success_mess(delete_successful);
                    //var url = M.cfg.wwwroot+"/local/blackboxsurvey/admin/questionlist.php";
                    //window.location = url;
                    question_search_result();
                }
                else if (msg == 'false'){//xoa that bai
                    $('#lodiv').html('<script>alert("The question has been used");</script>');
                }
                //$('#test').html(msg);
                
            },
            error: function()
            {
                alert('Can not delete question');
                $('#lodiv').hide();
                $('#lodiv').html('');
            }
        });	
    }	
}
/***********************************************************************************************
 * 											UNUSE aJAX fUNCTION
 ***********************************************************************************************/
//hien colorbox assign user role----UNUSE
function load_assign_role_colorbox(user_id)
{
    $.fn.colorbox({
			width:"350px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_assign_role&id="+user_id,
			title:"Assign Blackbox User Role",
			height:"150px", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
                load_user_table();
			}
    });
}
///UNUSE
function load_user_table(){
    $.ajax({
		  type: 'GET',
		  url: M.cfg.wwwroot+"/local/blackboxsurvey/ajax.php",
		  data: { 
                    "show": 'load_user_table'
                },
		  dataType: 'html',
		  success: function(msg){
			  $('#lecturertable').html(msg);
              filter();
		  },
	});
}

//hien colorbox assign user subject---UNUSE
function load_assign_subject_colorbox(user_id)
{
    $.fn.colorbox({
			width:"700px", 
			href:M.cfg.wwwroot+"/local/blackboxsurvey/colorbox/colorbox_content.php?show=load_assign_subject&id="+user_id,
			title:"Assign Blackbox User Role",
			height:"80%", 
			iframe:true, 
			onClosed:function(){
				//show_survey_question();
			}
    });
}

 //assign role cho user ---- UNUSE
 function assign_user_role(role_id)
 {
    if($('#cb'+role_id).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'assign_user_role',
                    "user_id": $('#id_txtid').val(),
                    "role_id": role_id,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }
 
  //assign subject cho user--UNUSE
 function assign_user_subject(subject_id)
 {
    if($('#cb'+subject_id).is(':checked')) {
        var action = "add";
    } else {
        var action = "remove";
    }
    $.ajax({
		  type: 'GET',
		  url: "../ajax.php",
		  data: { 
                    "show": 'assign_user_subject',
                    "user_id": $('#id_txtid').val(),
                    "subject_id": subject_id,
                    "action": action
                },
		  dataType: 'html',
		  success: function(msg){
 		 	//$('#questiontable').html(msg);
		  },
	});
 }

//thog bao cau hoi da dc su dung---UNUSE
function alert_unable(unuse_id)
{
    alert("This question has been used");
}

//thog bao survey da dc su dung---UNUSE
function alert_survey(unuse_id)
{
    alert("This survey is unable to delete/edit due to under Processing/Expired");
}






